package ModelLayer;
import java.util.ArrayList;
public class CustomerContainer
{
    public ArrayList<Customer> customerGroupContainer;
    public static CustomerContainer instance;
    public CustomerContainer()
    {
       customerGroupContainer = new ArrayList<Customer>();
    }
    public static CustomerContainer getSingelton()
    {
        if(instance == null)
        {
            instance = new CustomerContainer();
        }
        return instance;
    }
    public void addCustomer(Customer customer)
    {
        customerGroupContainer.add(customer);
    }
    public Customer findCustomer(String phone)
    {
        int index = 0;
        boolean found = false;
        while(index < customerGroupContainer.size() && !found)
        {
            if(customerGroupContainer.get(index).getPhoneNo().equals(phone))
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        return customerGroupContainer.get(index);
    }
    public boolean deleteCustomer(String phone)
    {
        Customer customer;
        int index = 0;
        boolean found = false;
        while(index < customerGroupContainer.size() && !found)
        {
            customer = customerGroupContainer.get(index);
            if(customerGroupContainer.get(index).getPhoneNo().equals(phone))
            {
                found = true;
                customerGroupContainer.remove(index);
            }
            else
            {
                index++;
            }
        }
        return found;
    }
    public ArrayList<Customer> listAllCustomer()
    {
        return customerGroupContainer;
    }
     public void updatePerson(String phone,String firstName, String lastName,String address, String zipCode, String city)
    {
        int index = 0;
        boolean found = false;
        while(index < customerGroupContainer.size() && !found)
        {
            if(customerGroupContainer.get(index).getPhoneNo() == phone)
            {
                if(firstName.length() > 0)
                {
                    customerGroupContainer.get(index).setPersonFirstName(firstName); 
                }
                else
                {
                    
                }
                if(lastName.length() > 0)
                {
                    customerGroupContainer.get(index).setPersonLastName(lastName);
                }
                else
                {
                    
                }
                if(address.length() > 0)
                {
                    customerGroupContainer.get(index).setAddress(address); 
                }
                else
                {
                    
                }
                if(zipCode.length() > 0)
                {
                    customerGroupContainer.get(index).setZipCode(zipCode);
                }
                else
                {
                    
                }
                if(city.length() > 0)
                {
                    customerGroupContainer.get(index).setCity(city);
                }
                else
                {
                    
                }
                found = true;
            }
            else
            {
                index++;
            }
        }
    }

   
   
}
